home *** CD-ROM | disk | FTP | other *** search
-
- // create a namespace for our Utils.
- var BartDOMUtils = BartModule.createNamespace("bart.ibrowser.DOMUtils");
-
- /**
- * Get current selected text in current document.
- * TODO: this is for Firefox only. Need to support other browsers.
- */
- BartDOMUtils.getSelectedText = function()
- {
- /*var focusedWindow = document.commandDispatcher.focusedWindow;
- var selection = focusedWindow.getSelection();
- if(selection)
- {
- selection = selection.toString().trim();
- }
-
- return selection;*/
- if (window.getSelection)
- {
- // This technique is the most likely to be standardized.
- // getSelection() returns a Selection object, which we do not document.
- return window.getSelection().toString();
- }
- else if (document.getSelection)
- {
- // This is an older, simpler technique that returns a string
- return document.getSelection();
- }
- else if (document.selection)
- {
- // This is the IE-specific technique.
- // We do not document the IE selection property or TextRange objects.
- return document.selection.createRange().text;
- }
- return "";
- };
-
-
- /**
- * Remove all children of a DOM object
- */
- BartDOMUtils.removeAllChildren = function(domObject)
- {
- if(domObject && domObject.childNodes
- && domObject.childNodes.length
- && (typeof domObject.childNodes.length == "number"))
- {
- while(domObject.childNodes.length > 0)
- {
- domObject.removeChild(domObject.childNodes[0]);
- }
- }
- };
-